<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">


    <title> 订单列表</title>
    <meta content="" name="keywords">
    <meta content="" name="description">

    <link href="favicon.ico" rel="shortcut icon">
    <link href="/static/hAdmin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/static/hAdmin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <!-- Sweet Alert -->
    <link href="/static/hAdmin/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="/static/hAdmin/css/animate.css" rel="stylesheet">
    <!--<link href="/static/hAdmin/css/style.css?v=4.1.0" rel="stylesheet">-->
    <link href="/static/hAdmin/css/style.css?version 4.0" rel="stylesheet">
    <link href="/static/hAdmin/css/plugins/toastr/toastr.min.css" rel="stylesheet">
    <style>
        .addList {
            padding: 10px 30px 10px 30px;
            height: 90px;
            margin-top: 3px
        }
    </style>

</head>

<body class="gray-bg animated bounceInDown">
<div id="block"
     style="width: 100%;height: 100%;background: #171717;opacity: 0.7;position: fixed;top: 0;left: 0;z-index: 999;text-align: center;display: none">
    <div style="margin-top: 300px">
        <span style="color: #ffffff;font-size: 20px;font-weight: 700">正在提交本次操作，请勿进行任何操作......</span>
    </div>
</div>
<div class="wrapper wrapper-content animated fadeInUp">
    <span id="gloUrl" style="display: none"></span>

    <div class="row">
        <div class="col-sm-12">

            <div class="ibox">
                <div class="ibox-title" style="height: 55px;">
                    <h5>所有记录</h5>
                    <div class="ibox-tools">
                        <div class="text-center">

                        </div>

                    </div>
                </div>
                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">
                        <div class="col-md-1">
                            <button class="btn btn-white btn-sm" id="loading-example-btn" type="button"><i
                                    class="fa fa-refresh"></i>
                                刷新
                            </button>
                        </div>
                        <div class="col-md-11 form-inline">
                            <div class="input-group col-xs-5">
                                <input class="input-sm form-control" id="searchKey"
                                       placeholder="请根据 景点/特色名称 进行关键词匹配"
                                       type="text">
                            </div>

                            <div class="input-group">
                                <button class="btn btn-sm btn-primary" id="getByKeywords"
                                        type="button">搜索
                                </button>
                            </div>
                        </div>
                    </div>
                    <!--            列表          -->
                    <div class="project-list">
                        <table class="table table-hover">
                            <tbody id="listBody"></tbody>
                        </table>
                    </div>
                    <!--                        页码控制-->
                    <div ajaxUrl="www.baidu.com" currentPage="1" id="pageHelper">
                        <div class="pageBottom col-xs-10 col-xs-offset-1" style="margin-top: 20px">
                            <nav aria-label="...">
                                <ul class="pager">
                                    <li class="previous disabled"><a href="javascript:void(0)"><span aria-hidden="true">&larr;</span>
                                        上一页</a></li>
                                    <li>
                                        <span>共</span>
                                        <span id="data_total">${total}</span>
                                        <span>条数据</span>
                                    </li>
                                    <li class="next"><a href="javascript:void(0)">下一页 <span
                                            aria-hidden="true">&rarr;</span></a></li>
                                </ul>
                            </nav>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<!--弹出框-->
<div aria-hidden="true" class="modal inmodal" id="myModal" role="dialog" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content animated bounceInRight" style="min-height: 400px;overflow-y: scroll">
            <div class="modal-header">
                <button class="close" data-dismiss="modal" type="button">
                    <span aria-hidden="true">&times;</span>
                    <span class="sr-only">关闭</span>
                </button>
                <i class="fa fa-users modal-icon" style="font-size: 60px"></i>
                <h4 class="modal-title">新增订单</h4>

            </div>

            <div class="formListAdd">


                <div class="modal-body addList">

                    <div class="form-group col-xs-12">
                        <label>封面照片</label>
                        <input type="file" id="insFile" required="required" multiple="multiple" name="file"
                               class="form-control"></div>
                </div>
                <div class="modal-body addList">
                    <div class="form-group col-xs-12">
                        <label>订单名称</label>
                        <input class="form-control" id="inscourseName" placeholder="输入订单备注" type="text"></div>
                </div>
                <div class="modal-body addList">
                    <div class="form-group col-xs-12">
                        <label>价格</label>
                        <input class="form-control" id="insprice" placeholder="输入价格" type="number"></div>
                </div>
                <div class="modal-body addList">
                    <div class="form-group col-xs-12">
                        <label>建议游玩时间</label>
                        <input class="form-control" id="inslearningCycle" placeholder="输入建议游玩时间" type="text"></div>
                </div>
                <div class="modal-body addList">
                    <div class="form-group col-xs-12">
                        <label>内容</label>
                        <textarea class="form-control" id="inscontent" placeholder="输入内容" type="number"></textarea></div>
                </div>

                <div class="modal-body addList">
                    <div class="form-group col-xs-12">
                        <label>当地名人</label>
                        <select id="insteacherId" class="form-control">

                        </select>
                    </div>
                </div>



                <div class="modal-footer">
                    <button class="btn btn-white" data-dismiss="modal" type="button">关闭</button>
                    <button class="btn btn-success" data-dismiss="modal" id="confirmAddEq" type="button">确定</button>
                </div>
            </div>
        </div>
    </div>
</div>

<!--弹出框-->
<div aria-hidden="true" class="modal inmodal" id="myModalEdit" role="dialog" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content animated bounceInRight" style="min-height: 400px;overflow-y: scroll">
            <div class="modal-header">
                <button class="close" data-dismiss="modal" type="button">
                    <span aria-hidden="true">&times;</span>
                    <span class="sr-only">关闭</span>
                </button>
                <i class="fa fa-users modal-icon" style="font-size: 60px"></i>
                <h4 class="modal-title">编辑订单</h4>

            </div>

            <div class="formListAdd">
                <div class="modal-body addList">

                    <div class="form-group col-xs-12">
                        <label>封面照片</label>
                        <input type="file" id="editFile" required="required" multiple="multiple" name="file"
                               class="form-control"></div>
                </div>
                <div class="modal-body addList">
                    <div class="form-group col-xs-12">
                        <label>订单名称</label>
                        <input class="form-control" id="editcourseName" placeholder="输入订单备注" type="text"></div>
                </div>
                <div class="modal-body addList">
                    <div class="form-group col-xs-12">
                        <label>价格</label>
                        <input class="form-control" id="editprice" placeholder="输入价格" type="number"></div>
                </div>
                <div class="modal-body addList">
                    <div class="form-group col-xs-12">
                        <label>建议游玩时间</label>
                        <input class="form-control" id="editlearningCycle" placeholder="输入建议游玩时间" type="text"></div>
                </div>
                <div class="modal-body addList">
                    <div class="form-group col-xs-12">
                        <label>内容</label>
                        <textarea class="form-control" id="editcontent" placeholder="输入内容" type="number"></textarea></div>
                </div>

                <div class="modal-body addList">
                    <div class="form-group col-xs-12">
                        <label>当地名人</label>
                        <select id="editteacherId" class="form-control">

                        </select>
                    </div>
                </div>

                <div class="modal-footer">
                    <button class="btn btn-white" data-dismiss="modal" type="button">关闭</button>
                    <button class="btn btn-success" data-dismiss="modal" id="confirmEditEq" type="button">确定</button>
                </div>
            </div>
        </div>
    </div>
</div>

<!--上传电子入场券弹出框-->
<div aria-hidden="true" class="modal inmodal" id="myModalAddFile" role="dialog" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content animated bounceInRight" style="min-height: 400px;overflow-y: scroll">
            <div class="modal-header">
                <button class="close" data-dismiss="modal" type="button">
                    <span aria-hidden="true">&times;</span>
                    <span class="sr-only">关闭</span>
                </button>
                <i class="fa fa-users modal-icon" style="font-size: 60px"></i>
                <h4 class="modal-title">更新订单电子纪念券</h4>

            </div>

            <div class="formListAdd">


                <div class="modal-body addList">

                    <div class="form-group col-xs-12">
                        <label>文件</label>
                        <input type="file" id="insCourseFile" required="required" multiple="multiple" name="file"
                               class="form-control"></div>
                </div>
                <div class="modal-body.page2 addList">
                    <div class="form-group col-xs-12">
                        <label>文件名称</label>
                        <input class="form-control" id="insfileName" placeholder="输入文件名称" type="text"></div>
                </div>



                <div class="modal-footer">
                    <button class="btn btn-white" data-dismiss="modal" type="button">关闭</button>
                    <button class="btn btn-success" data-dismiss="modal" id="confirmAddFile" type="button">确定</button>
                </div>
            </div>
        </div>
    </div>
</div>


<!-- 全局js -->
<script src="/static/hAdmin/js/jquery.min.js?v=2.1.4"></script>
<script src="/static/hAdmin/js/bootstrap.min.js?v=3.3.6"></script>
<!-- Sweet alert -->
<script src="/static/hAdmin/js/plugins/sweetalert/sweetalert.min.js"></script>

<!-- 自定义js -->
<script src="/static/hAdmin/js/content.js?v=1.0.0"></script>
<!--    分页js -->
<!--<script src="/static/wmmJs/public/PageHelper.js"></script>-->
<script src="/static/hAdmin/js/plugins/toastr/toastr.min.js"></script>
<script src="/static/js/GloJs.js"></script>
<script>


    $(function () {

        let Glo_BaseUrl = $("#gloUrl").attr("gloUValue")
        let Glo_user = localStorage.getItem("userId")
        let currentPage = $("#pageHelper").attr("currentPage");

        //获取当地名人列表
        function getSchedulingTempList(){

            $.ajax({
                url: Glo_BaseUrl + "/teacher/list",
                type: "get",
                data:{
                    "pageSize": 999,
                    "pageNum": 1,

                },
                success: function (data) {
                    $("#instemplateId").html("").append(`<option value="">请选择当地名人</option>`)
                    for (let i = 0; i < data.list.length; i++) {
                        let item = data.list[i]
                        $("#insteacherId").append(` <option value="${item.id}">${item.username}</option>`)
                        $("#editteacherId").append(` <option value="${item.id}">${item.username}</option>`)
                    }


                },
                error: function () {
                    alert("服务器异常！network error！")
                }
            })
        }
        getSchedulingTempList()


        function getContractList(num) {
            let total = 0;//总数
            let pageSize = 6;//每页条数
            let html_dom = $("#listBody")

            let searchKey = $("#searchKey").val()
            if (num === 1) {
                searchKey = ""
                $("#searchKey").val("")
            }
            setTimeout(function () {
                $.ajax({
                    url: Glo_BaseUrl + "/order/list",
                    type: "get",
                    data: {
                        "pageSize": pageSize,
                        "pageNum": currentPage,
                        "courseName": searchKey,

                    },
                    success: function (data) {
                        let ListStr = ''
                        total = data.total
                        for (let i = 0; i < data.list.length; i++) {
                            let item = data.list[i]
                            let controlBtn = `

<a href="javascript:void(0)" class="btn btn-danger btn-sm toDelete " id="toDelete_${data.list[i].id}"><i class="fa fa-trash"></i> 删除 </a>

`
                            let statusStr =``
                            statusStr = `<span class="label label-info">${item.learningCycle}</span>`;
                            ListStr +=
                                `<tr>
                                          <td class="project-completion">
                                              <img src="${item.pic}" style="width: 100px;height: 100px;" alt="">
                </td>
                                        <td class="project-title">
                                            <span >
                                            <strong>
                                 景点/特色名称:  ${item.courseName}（${item.status}）

                                            </strong>
                                             </span>
                                            <br/>
                                              <small>价格：<span id="EventTime">${data.list[i].price}</span> </small>
                                        </td>
                <td class="project-completion">
                                                <small>下单时间：<span id="dataForClass">${data.list[i].createTime}</span> </small>
                </td>
    <td class="project-completion">
                                                <small>支付时间：<span id="dataForClass">${data.list[i].updateTime}</span> </small>
                </td>

                  <td class="project-completion">
                                                <small>用户姓名：<span id="dataForClass">${data.list[i].userName}</span> </small>
                </td>   <!--<td class="project-completion">
                                                <small>内容：<span id="dataForClass">${data.list[i].content}</span> </small>
                </td>-->
                <td class="project-actions">
                ` + controlBtn +
                                `
                </td>
                </tr>
                `
                        }

                        if (data.code !== 500) {
                            html_dom.html("")
                            html_dom.append(ListStr)
                            getRoleSetMenu()
                        } else {
                            alert("获取失败")
                        }
                        total = data.total
                        $("#data_total").html(data.total);

                        //下一页
                        $('.next').unbind().click(function () {
                            if (currentPage * pageSize >= total) {
                                toastr.error("已经是最后一页了！", '提醒')
                            } else {
                                currentPage++;
                                $("#pageHelper").attr("currentPage", currentPage);
                                if (currentPage > 0) {
                                    $(".previous").removeClass("disabled")
                                }
                                $(".project-list").addClass("animated bounceOutLeft")
                                setTimeout(function () {
                                    $(".project-list").removeClass("animated bounceOutLeft").addClass("animated bounceInRight")
                                }, 500)
                                getContractList(2)
                            }

                        });
                        //上一页
                        $('.previous').unbind().click(function () {
                            currentPage--;
                            $("#pageHelper").attr("currentPage", currentPage);
                            if (currentPage === 0) {
                                currentPage = 1;
                                $("#pageHelper").attr("currentPage", currentPage);
                                $(".previous").addClass("disabled");
                            } else {
                                $(".project-list").addClass("animated bounceOutRight")
                                setTimeout(function () {
                                    $(".project-list").removeClass("animated bounceOutRight bounceInRight").addClass("animated bounceInLeft")
                                }, 500)
                                getContractList(2)
                            }
                        });
                        //删除订单信息
                        $(".toDelete").unbind().click(function () {
                            let id = $(this).attr("id").split("toDelete_")[1]
                            swal({
                                title: "您确定要删除该订单信息吗",
                                text: "删除后不可恢复！",
                                type: "warning",
                                showCancelButton: true,
                                confirmButtonColor: "#DD6B55",
                                confirmButtonText: "删除",
                                closeOnConfirm: false
                            }, function () {
                                $.ajax({
                                    url: Glo_BaseUrl + "/order/del",
                                    type: "post",
                                    data: {
                                        id: id,
                                    },
                                    success: function (data) {
                                        windowsAuto(data.code, data.msg)
                                        getContractList(2)
                                    },
                                    error: function () {
                                        alert("服务器异常！network error！")
                                    }
                                })

                            });

                        });



                        //编辑
                        $(".editContract").unbind().click(function () {
                            localStorage.setItem("id", $(this).attr("thisId"));
                            $("#editcourseName").val($(this).attr("thiscourseName"));
                            $("#editprice").val($(this).attr("thisprice"));
                            $("#editcontent").val($(this).attr("thiscontent"));
                            $("#editlearningCycle").val($(this).attr("thislearningCycle"));
                            $("#editteacherId").val($(this).attr("thisteacherId"));

                        });


                    },
                    error: function () {
                        alert("服务器异常！network error！")
                    }
                });
            }, 300)
        }


        //*******************************************
        getContractList(2)
        $("#getByKeywords").click(function () {
            getContractList(2)
        })
        $(".loading-example-btn").click(function () {
            getContractList(1)
        })

        // beginPage()
        function simpleLoad(btn, state) {
            if (state) {
                btn.children().addClass('fa-spin');
                btn.contents().last().replaceWith(" Loading");
            } else {
                setTimeout(function () {
                    btn.children().removeClass('fa-spin');
                    btn.contents().last().replaceWith(" Refresh");
                }, 2000);
            }
        }

        $(document).ready(function () {
            $('#loading-example-btn').click(function () {
                btn = $(this);
                simpleLoad(btn, true)
                simpleLoad(btn, false)
                getContractList(1)
            });
        });


//-----------------------------
        //添加订单
        $("#confirmAddEq").click(function () {

            var formData = new FormData();//这里需要实例化一个FormData来进行文件上传

            if ($("#insFile")[0].files[0] != undefined){
                formData.append("file",$("#insFile")[0].files[0]);
            }
            formData.append("courseName", $("#inscourseName").val());
            formData.append("price", $("#insprice").val());

            formData.append("content", $("#inscontent").val() );
            formData.append("learningCycle", $("#inslearningCycle").val() );
            formData.append("teacherId", $("#insteacherId").val() );


            $.ajax({
                url: Glo_BaseUrl + "/order/add",
                type: "post",
                data: formData,
                processData: false,
                contentType: false,
                success: function (data) {
                    if (data.code === 200) {
                        toastr.success(data.msg, '提示')
                    } else {
                        toastr.error(data.msg, '提示')
                    }
                    getContractList()
                },
                error: function () {
                    alert("服务器异常！network error！")
                }
            })
        })

        //编辑订单
        $("#confirmEditEq").click(function () {
            var formData = new FormData();//这里需要实例化一个FormData来进行文件上传

            if ($("#editFile")[0].files[0] != undefined){
                formData.append("file",$("#editFile")[0].files[0]);
            }
            formData.append("courseName", $("#editcourseName").val());
            formData.append("price", $("#editprice").val());

            formData.append("content", $("#editcontent").val() );
            formData.append("learningCycle", $("#editlearningCycle").val() );
            formData.append("teacherId", $("#editteacherId").val() );
            formData.append("id", localStorage.getItem("id") );

            $.ajax({
                url: Glo_BaseUrl + "/order/edit",
                type: "post",
                data: formData,
                processData: false,
                contentType: false,
                success: function (data) {
                    if (data.code === 200) {
                        toastr.success(data.msg, '提示')
                    } else {
                        toastr.error(data.msg, '提示')
                    }


                    getContractList()
                },
                error: function () {
                    alert("服务器异常！network error！")
                }
            })
        })

       //编辑电子入场券
        $("#confirmAddFile").click(function () {
            var formData = new FormData();//这里需要实例化一个FormData来进行文件上传

            if ($("#insCourseFile")[0].files[0] != undefined){
                formData.append("file",$("#insCourseFile")[0].files[0]);
            }
            formData.append("fileName", $("#insfileName").val());

            formData.append("courseId", localStorage.getItem("id") );

            $.ajax({
                url: Glo_BaseUrl + "/tFile/add",
                type: "post",
                data: formData,
                processData: false,
                contentType: false,
                success: function (data) {
                    if (data.code === 200) {
                        toastr.success(data.msg, '提示')
                    } else {
                        toastr.error(data.msg, '提示')
                    }


                    getContractList()
                },
                error: function () {
                    alert("服务器异常！network error！")
                }
            })
        })


    })
</script>
</body>
</html>
